package com.ruoyi.web.controller.control;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.control.domain.UseElectricity;
import com.ruoyi.control.service.IUseElectricityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 智能用电Controller
 *
 * @author ruoyi
 * @date 2024-12-18
 */
@RestController
@RequestMapping("/useElectricity/useElectricity")
public class UseElectricityController extends BaseController
{
    @Autowired
    private IUseElectricityService useElectricityService;

    /**
     * 查询智能用电列表
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:list')")
    @GetMapping("/list")
    public TableDataInfo list(UseElectricity useElectricity)
    {
        startPage();
        List<UseElectricity> list = useElectricityService.selectUseElectricityList(useElectricity);
        return getDataTable(list);
    }

    /**
     * 导出智能用电列表
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:export')")
    @Log(title = "智能用电", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UseElectricity useElectricity)
    {
        List<UseElectricity> list = useElectricityService.selectUseElectricityList(useElectricity);
        ExcelUtil<UseElectricity> util = new ExcelUtil<UseElectricity>(UseElectricity.class);
        util.exportExcel(response, list, "智能用电数据");
    }

    /**
     * 获取智能用电详细信息
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:query')")
    @GetMapping(value = "/{tagName}")
    public AjaxResult getInfo(@PathVariable("tagName") String tagName)
    {
        return success(useElectricityService.selectUseElectricityByTagName(tagName));
    }

    /**
     * 新增智能用电
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:add')")
    @Log(title = "智能用电", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UseElectricity useElectricity)
    {
        return toAjax(useElectricityService.insertUseElectricity(useElectricity));
    }

    /**
     * 修改智能用电
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:edit')")
    @Log(title = "智能用电", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UseElectricity useElectricity)
    {
        return toAjax(useElectricityService.updateUseElectricity(useElectricity));
    }

    /**
     * 删除智能用电
     */
    @PreAuthorize("@ss.hasPermi('useElectricity:useElectricity:remove')")
    @Log(title = "智能用电", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagNames}")
    public AjaxResult remove(@PathVariable String[] tagNames)
    {
        return toAjax(useElectricityService.deleteUseElectricityByTagNames(tagNames));
    }
}
